<?php include_once('header.php');?>
	<div class="main-content">
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			<ul class="breadcrumb">
				<li>
					<i class="icon-home home-icon"></i>
					保险管理
				</li>
				<li>
					保险险种列表
				</li>
			</ul>
		</div>
		<div class="page-content">
			<div class="page-header">
				<h1 class="blue"><i class="icon-edit"></i> 编辑保险险种信息</h1>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<form class="form-horizontal" enctype="multipart/form-data" role="form" method="post" action="/www/insurance/edit"  onsubmit="return check()">
						<input type="hidden" id="id" name="id" value="<?php echo $data['id'];?>" />
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">险种名称:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="name" name="name" value="<?php echo $data['name'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">默认保额:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="sum_default" name="sum_default" value="<?php echo $data['sum_default'];?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">所属套餐:</label>
							<div class="col-sm-6">
								<?php 
									foreach($version_list as $key => $value) {
										if(in_array($value['id'], $id_array)) {											
											echo '<label><input name="version_id[]" type="checkbox" checked="checked" value="'.$value['id'].'" />'.$value['version_name'].' </label>&nbsp;&nbsp;&nbsp;';
										}else {
											echo '<label><input name="version_id[]" type="checkbox" value="'.$value['id'].'" />'.$value['version_name'].' </label>&nbsp;&nbsp;&nbsp;';											
										}									
									}
								?>
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">默认开关:</label>
							<div class="col-sm-6">											
								<select name="button_status" id="button_status">
										<option value="1" <?php if($data['button_status'] == 1) {echo 'selected = "selected"';}?>>开</option>
										<option value="0" <?php if($data['button_status'] == 0) {echo 'selected = "selected"';}?>>关</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额1:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="sum_list[]" value="<?php if(isset($sum_list[0])) {echo $sum_list[0];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额2:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="sum_list[]" value="<?php if(isset($sum_list[1])) {echo $sum_list[1];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额3:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="sum_list[]" value="<?php if(isset($sum_list[2])) {echo $sum_list[2];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额4:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="sum_list[]" value="<?php if(isset($sum_list[3])) {echo $sum_list[3];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额5:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="sum_list[]" value="<?php if(isset($sum_list[4])) {echo $sum_list[4];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额6:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="sum_list[]" value="<?php if(isset($sum_list[5])) {echo $sum_list[5];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额7:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="sum_list[]" value="<?php if(isset($sum_list[6])) {echo $sum_list[6];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额8:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" name="sum_list[]" value="<?php if(isset($sum_list[7])) {echo $sum_list[7];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">可选保额9:</label>
							<div class="col-sm-6">
								<input type="text" class="form-control"  name="sum_list[]" value="<?php if(isset($sum_list[8])) {echo $sum_list[8];}?>">
							</div>
						</div>
						<div class="form-group">
							<label for="title" class="col-sm-1 control-label">备注:</label>
							<div class="col-sm-6">
								<textarea class="form-control" rows="4" name="remark"><?php echo $data['remark'];?></textarea>
							</div>
						</div>
					 	<div class="form-group">
					   		<div class="col-sm-offset-1 col-sm-10">
								<button type="submit" id="submit" class="btn btn-primary">确定</button>
								<button type="submit" id="cancel" class="btn btn-primary">取消</button>
							</div>
					  	</div>
					</form>	
				</div>
			</div>					
		</div>													
	</div>
<?php include_once('content.php');?>
	<link href="/public_source/www/assets/css/ace.min.css" rel="stylesheet" />	
	<link href="/public_source/www/assets/css/jquery.tag-editor.css" rel="stylesheet"/>
    <script src="/public_source/www/assets/js/bootbox.min.js"></script>  
	<script src="/public_source/www/assets/js/jquery.tag-editor.min.js"></script>
	<script src="/public_source/www/js/areas.js"></script>
<?php include_once('footer.php');?>	
<script type="text/javascript">
	$(document).ready(function(){
		$("#cancel").click(function() {
			window.location.replace('/www/insurance/insurance_list');
			return false;
		});
	});
	function check() {
	   var name = document.getElementById("name").value;
	   var id = document.getElementById("id").value;
	   var sum_default = document.getElementById("sum_default").value;
	   var version_id = document.getElementsByName("version_id[]");
	   var data = {name:name,id:id};
	   var bool = true;
	   if(name ==  null || name == '') {
	        alert("险种名不能为空");
	        return false;
	   }
	   if(sum_default ==  null || sum_default == '') {
	        alert("默认保额不能为空");
	        return false;
	   }	
	   var id_bool = false;   
	   for(var i = 0;i < version_id.length;++i) {	   
			if(version_id[i].checked == true) {
				id_bool = true;
			}		   
		}
	   if(!id_bool) {
	        alert("请选择所属套餐");
	        return false;
	   }
	   $.ajax({
			url:"/www/insurance/check_sole",
			async: false,
			type:"post",
			data: data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}	
		});
		if(!bool) {
			 alert("险种名已存在");
			 return false;	
		}
	   return true;
	}			
</script>		